<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Login</title>
</head>
<script src="js/jquery-2.1.0.min.js"></script>
<body>
<h2>登录</h2>
<form id="loginForm">
    <label for="username">账号:</label>
    <input type="text" id="username" name="username" required><br><br>
    <label for="password">密码:</label>
    <input type="password" id="password" name="password" required><br><br>
    <button type="submit">Login</button>
</form>
</body>
<script>
    $('#loginForm').submit(function (event) {
        event.preventDefault();  // 阻止表单默认提交
        var username = $('#username').val();
        var password = $('#password').val();
        $.ajax({
            url: "/admin/login",
            method: "post",
            dataType: "json",
            contentType: "application/json",  // 指定请求头为 JSON
            data: JSON.stringify({
                username: username,
                password: password
            }),
            success: function (ret) {
                console.log(ret)
                if (ret.code == 2000) {
                    console.log(ret.msg)
                    alert(ret.msg)
                    window.location.href = '/student.html'
                } else {
                    alert(ret.msg)
                    window.location.href = '/404.html'
                }
            }
        })
    })

</script>
</html>